package Schepen;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
/**
 * 
 * @author Ken Veensta
 * Goliath panel.
 * TODO list
 * 	- average drone level
 * 	- laserselection
 *  - 
 */

@SuppressWarnings("serial")
public class Goliath extends JPanel {
	private JButton calculate;
	private JComboBox r_damage, t_scheepsromp, t_premiejager, t_schildenergie, t_raketgeleerde;
	private JPanel leftPanel, rightPanel;
	private JTextField s_laser3, s_gen, s_shield, d_laser3, d_shield, u_shield,
				u_damage, u_damage4, u_damage6, u_speed, u_rDamage, u_health;
	private ButtonGroup laserSelect, rocketSelect, genSelect, shieldSelect, designSelect,
				damageboosterSelect, shieldboosterSelect, hpboosterSelect;
	private JRadioButton l_Seprom, l_promerium, l_none, r_Seprom, r_promerium, r_none, s_Seprom, 
				s_promerium, s_none, g_promerium, g_none, design_Damage, design_Defence, design_none,
				bd_double, bd_single, bd_none, bs_double, bs_single, bs_none, bh_double, bh_single, bh_none;
	boolean doL_Seprom, doL_prom, doR_Seprom, doR_prom, doS_Seprom, doS_prom, doG_prom, des_dam, des_def, 
				db_2, db_1, sb_1, sb_2, hb_1, hb_2;
	private final int startHP = 256000;
	private final int startSpeed = 300;
	private final int generators = 15;
	private final int lasers = 15;
	private final int dr_max = 16;

	public Goliath() {

		setLayout(new BorderLayout());

		leftPanel = new JPanel();
		leftPanel.setLayout(new GridLayout(15, 2));
		rightPanel = new JPanel();
		rightPanel.setLayout(new GridLayout(15, 4));

		makeLeftObjects();	// makes left panel objects etc.
		makeRightObjects();	// makes right panel objects etc.

		/*
		 * this adds all contents to the leftpanel
		 */
		
		leftPanel.add(new JLabel("Goliath k2"));
		leftPanel.add(new JLabel("only for a full elite goliath"));
		leftPanel.add(new JLabel("Ship Lasers (only LF3)"));
		leftPanel.add(s_laser3);
		leftPanel.add(new JLabel("Ship speedgens (g3n-7900)"));
		leftPanel.add(s_gen);
		leftPanel.add(new JLabel("Ship shieldgens (SG3N-B02)"));
		leftPanel.add(s_shield);
		leftPanel.add(new JLabel("Drone lasers (LF3)"));
		leftPanel.add(d_laser3);
		leftPanel.add(new JLabel("Drone shield (SG3N-B02)"));
		leftPanel.add(d_shield);
		leftPanel.add(new JLabel("Rocket type"));
		leftPanel.add(r_damage);
		leftPanel.add(new JLabel(""));
		leftPanel.add(calculate);
		leftPanel.add(new JLabel("Total hit points"));
		leftPanel.add(u_health);
		leftPanel.add(new JLabel("Average x1 damage"));
		leftPanel.add(u_damage);
		leftPanel.add(new JLabel("Average x4 damage"));
		leftPanel.add(u_damage4);
		leftPanel.add(new JLabel("Average RSB-75 damage"));
		leftPanel.add(u_damage6);
		leftPanel.add(new JLabel("Average rocket damage"));
		leftPanel.add(u_rDamage);
		leftPanel.add(new JLabel("Total shield"));
		leftPanel.add(u_shield);
		leftPanel.add(new JLabel("Total speed"));
		leftPanel.add(u_speed);

		/*
		 * this adds all the contents to the rightPanel.
		 */
		
		rightPanel.add(new JLabel("Laser updates: "));
		rightPanel.add(l_Seprom);
		rightPanel.add(l_promerium);
		rightPanel.add(l_none);
		
		rightPanel.add(new JLabel("Rocket updates: "));
		rightPanel.add(r_Seprom);
		rightPanel.add(r_promerium);
		rightPanel.add(r_none);

		rightPanel.add(new JLabel("Shield updates: "));
		rightPanel.add(s_Seprom);
		rightPanel.add(s_promerium);
		rightPanel.add(s_none);

		rightPanel.add(new JLabel("Speed updates: "));
		rightPanel.add(new JLabel(""));
		rightPanel.add(g_promerium);
		rightPanel.add(g_none);
		
		rightPanel.add(new JLabel(""));rightPanel.add(new JLabel(""));rightPanel.add(new JLabel(""));rightPanel.add(new JLabel(""));

		rightPanel.add(new JLabel("Design extra:"));
		rightPanel.add(design_Damage);
		rightPanel.add(design_Defence);
		rightPanel.add(design_none);
		
		rightPanel.add(new JLabel(""));rightPanel.add(new JLabel(""));rightPanel.add(new JLabel(""));rightPanel.add(new JLabel(""));

		rightPanel.add(new JLabel("Damage booster:"));
		rightPanel.add(bd_double);
		rightPanel.add(bd_single);
		rightPanel.add(bd_none);

		rightPanel.add(new JLabel("Shield booster:"));
		rightPanel.add(bs_double);
		rightPanel.add(bs_single);
		rightPanel.add(bs_none);
		
		rightPanel.add(new JLabel("Health booster:"));
		rightPanel.add(bh_double);
		rightPanel.add(bh_single);
		rightPanel.add(bh_none);
		
		rightPanel.add(new JLabel(""));rightPanel.add(new JLabel(""));rightPanel.add(new JLabel(""));rightPanel.add(new JLabel(""));
		
		rightPanel.add(new JLabel("Ship hull I+II"));
		rightPanel.add(t_scheepsromp);
		rightPanel.add(new JLabel("  Bounty hunter I+II"));
		rightPanel.add(t_premiejager);

		rightPanel.add(new JLabel("Schield engineering"));
		rightPanel.add(t_schildenergie);
		rightPanel.add(new JLabel("  Rocket fusion"));
		rightPanel.add(t_raketgeleerde);
		
		for (int i = 0; i < 8; i++) {
			rightPanel.add(new JLabel(""));	//fills up the empty spaces
		}
		
		makeGroup();
		
		//makes the panel visible
		add(leftPanel, BorderLayout.CENTER);
		add(rightPanel, BorderLayout.EAST);
	}
	/*
	 * create the objects etc for the rightPanel.
	 */
	private void makeRightObjects() {
		//Laserupdates
		l_Seprom = new JRadioButton("Seprom");
		l_Seprom.setActionCommand("l_Seprom");
		l_promerium = new JRadioButton("Promerium");
		l_promerium.setActionCommand("l_Promerium");
		l_none = new JRadioButton("none");
		l_none.setActionCommand("l_none");
		l_none.setSelected(true);

		l_Seprom.addActionListener(new BooleanHandler());
		l_promerium.addActionListener(new BooleanHandler());
		l_none.addActionListener(new BooleanHandler());
		
		//rocketupdates
		r_Seprom = new JRadioButton("Seprom");
		r_Seprom.setActionCommand("r_Seprom");
		r_promerium = new JRadioButton("Promerium");
		r_promerium.setActionCommand("r_Promerium");
		r_none = new JRadioButton("none");
		r_none.setActionCommand("r_none");
		r_none.setSelected(true);

		r_Seprom.addActionListener(new BooleanHandler());
		r_promerium.addActionListener(new BooleanHandler());
		r_none.addActionListener(new BooleanHandler());
		
		//shieldupdates
		s_Seprom = new JRadioButton("Seprom");
		s_Seprom.setActionCommand("s_Seprom");
		s_promerium = new JRadioButton("Promerium");
		s_promerium.setActionCommand("s_Promerium");
		s_none = new JRadioButton("none");
		s_none.setActionCommand("s_none");
		s_none.setSelected(true);

		s_Seprom.addActionListener(new BooleanHandler());
		s_promerium.addActionListener(new BooleanHandler());
		s_none.addActionListener(new BooleanHandler());
		
		//speedgen updates
		g_promerium = new JRadioButton("Promerium");
		g_promerium.setActionCommand("g_Promerium");
		g_none = new JRadioButton("none");
		g_none.setActionCommand("g_none");
		g_none.setSelected(true);

		g_promerium.addActionListener(new BooleanHandler());
		g_none.addActionListener(new BooleanHandler());
		
		//design update
		design_Damage = new JRadioButton("5% damage");
		design_Damage.setActionCommand("design_Damage");
		design_Defence = new JRadioButton("10% shield");
		design_Defence.setActionCommand("design_Defence");
		design_none = new JRadioButton("none");
		design_none.setActionCommand("design_none");
		design_none.setSelected(true);

		design_Damage.addActionListener(new BooleanHandler());
		design_Defence.addActionListener(new BooleanHandler());
		design_none.addActionListener(new BooleanHandler());
		
		//damage booster
		bd_double = new JRadioButton("double (20%)");
		bd_double.setActionCommand("bd_double");
		bd_single = new JRadioButton("single (10%)");
		bd_single.setActionCommand("bd_single");
		bd_none = new JRadioButton("none");
		bd_none.setActionCommand("bd_none");
		bd_none.setSelected(true);

		bd_double.addActionListener(new BooleanHandler());
		bd_single.addActionListener(new BooleanHandler());
		bd_none.addActionListener(new BooleanHandler());
		
		//shield booster
		bs_double = new JRadioButton("double (50%)");
		bs_double.setActionCommand("bs_double");
		bs_single = new JRadioButton("single (25%)");
		bs_single.setActionCommand("bs_single");
		bs_none = new JRadioButton("none");
		bs_none.setActionCommand("bs_none");
		bs_none.setSelected(true);

		bs_double.addActionListener(new BooleanHandler());
		bs_single.addActionListener(new BooleanHandler());
		bs_none.addActionListener(new BooleanHandler());
		
		//healthbooster
		bh_double = new JRadioButton("double (20%)");
		bh_double.setActionCommand("bh_double");
		bh_single = new JRadioButton("single (10%)");
		bh_single.setActionCommand("bh_single");
		bh_none = new JRadioButton("none");
		bh_none.setActionCommand("bh_none");
		bh_none.setSelected(true);

		bh_double.addActionListener(new BooleanHandler());
		bh_single.addActionListener(new BooleanHandler());
		bh_none.addActionListener(new BooleanHandler());
		
		String[] scheepsromp = {"  I: 0/2 (none)","  I: 1/2 (5.000 hp)" ,"  I: 2/2 (10.000 hp)"," II: 1/3 (15.000 hp)" ,
							" II: 2/3 (30.000 hp)", " II: 3/3 (50.000 hp)"};
		t_scheepsromp = new JComboBox(scheepsromp);
		String[] premiejager = {"  I: 0/2 (none)","  I: 1/2 (2%)" ,"  I: 2/2 (4%)"," II: 1/3 (6%)" ,
							" II: 2/3 (9%)", " II: 3/3 (12%)"};
		t_premiejager = new JComboBox(premiejager);
		String[] schildenergie = {"  I: 0/5 (none)","  I: 1/5 (4% shield)" ,"  I: 2/5 (8% shield)","  I: 3/5 (12% shield)" ,
							"  I: 4/5 (18% shield)", "  I: 5/5 (25% shield)"};
		t_schildenergie = new JComboBox(schildenergie);
		String[] raketgeleerde = {"  I: 0/5 (none)","  I: 1/5 (2%)" ,"  I: 2/5 (?%)","  I: 3/5 (?%)" ,
							"  I: 4/5 (?%)", "  I: 5/5 (15%)"};
		t_raketgeleerde = new JComboBox(raketgeleerde);
	}
	/*
	 * create the objects etc for the leftPanel.
	 */
	private void makeLeftObjects() {
		String[] raketten = { "R310", "PLT-2026", "PLT-2021", "PLT-3030" };

		s_laser3 = new JTextField(10);
		s_laser3.setText("0");
		r_damage = new JComboBox(raketten);
		s_gen = new JTextField(10);
		s_gen.setText("0");
		s_shield = new JTextField(10);
		s_shield.setText("0");
		d_laser3 = new JTextField(10);
		d_laser3.setText("0");
		d_shield = new JTextField(10);
		d_shield.setText("0");

		u_health = new JTextField(10);
		u_shield = new JTextField(10);
		u_damage = new JTextField(10);
		u_damage4 = new JTextField(10);
		u_damage6 = new JTextField(10);
		u_rDamage = new JTextField(10);
		u_speed = new JTextField(10);
		
		calculate = new JButton("Calculate");
		calculate.addActionListener(new InputHandler());
	}
	/*
	 * create's the buttongroups for the update's, boosters etc
	 */
	private void makeGroup() {
		laserSelect = new ButtonGroup();
		laserSelect.add(l_Seprom);
		laserSelect.add(l_promerium);
		laserSelect.add(l_none);
		
		rocketSelect = new ButtonGroup();
		rocketSelect.add(r_Seprom);
		rocketSelect.add(r_promerium);
		rocketSelect.add(r_none);
		
		shieldboosterSelect = new ButtonGroup();
		shieldboosterSelect.add(bs_double);
		shieldboosterSelect.add(bs_single);
		shieldboosterSelect.add(bs_none);
		
		hpboosterSelect = new ButtonGroup();
		hpboosterSelect.add(bh_double);
		hpboosterSelect.add(bh_single);
		hpboosterSelect.add(bh_none);
		
		damageboosterSelect = new ButtonGroup();
		damageboosterSelect.add(bd_double);
		damageboosterSelect.add(bd_single);
		damageboosterSelect.add(bd_none);
		
		designSelect = new ButtonGroup();
		designSelect.add(design_Damage);
		designSelect.add(design_Defence);
		designSelect.add(design_none);
		
		shieldSelect = new ButtonGroup();
		shieldSelect.add(s_Seprom);
		shieldSelect.add(s_promerium);
		shieldSelect.add(s_none);
		
		genSelect = new ButtonGroup();
		genSelect.add(g_promerium);
		genSelect.add(g_none);
	}
	/*
	 * this inner class functions as a extra handler (program will be a little faster now)
	 * if a button is set to another point this will instantly change the boolean before the calculation
	 * this is faster than you put it all in only 1 ActionListener.
	 */
	class BooleanHandler implements ActionListener {
		public void actionPerformed(ActionEvent b) {
			if (b.getActionCommand().equals("l_Seprom")) {doL_Seprom = true;  doL_prom = false;}
			if (b.getActionCommand().equals("l_Promerium")){doL_prom = true; doL_Seprom = false;}
			if (b.getActionCommand().equals("l_none")){doL_Seprom = false; doL_prom = false;}
			if (b.getActionCommand().equals("r_Seprom")) {doR_Seprom = true; doR_prom = false;}
			if (b.getActionCommand().equals("r_Promerium")){doR_prom = true; doR_Seprom = false;}
			if (b.getActionCommand().equals("r_none")){doR_Seprom = false; doR_prom = false;}
			if (b.getActionCommand().equals("s_Seprom")) {doS_Seprom = true; doS_prom = false;}
			if (b.getActionCommand().equals("s_Promerium")){doS_prom = true; doS_Seprom = false;}
			if (b.getActionCommand().equals("s_none")){doS_Seprom = false; doS_prom = false;}
			if (b.getActionCommand().equals("g_Promerium")){doG_prom = true;}
			if (b.getActionCommand().equals("g_none")){doG_prom = false;}
			if (b.getActionCommand().equals("design_Damage")) {des_dam = true; des_def = false;}
			if (b.getActionCommand().equals("design_Defence")){des_def = true; des_dam = false;}
			if (b.getActionCommand().equals("design_none")){des_dam = false; des_def = false;}
			if (b.getActionCommand().equals("bd_double")) {db_2 = true; db_1 = false;}
			if (b.getActionCommand().equals("bd_single")) {db_1 = true; db_2 = false;}
			if (b.getActionCommand().equals("bd_none")){db_2 = false; db_1 = false;}
			if (b.getActionCommand().equals("bs_double")) {sb_2 = true; sb_1 = false;}
			if (b.getActionCommand().equals("bs_single")) {sb_1 = true; sb_2 = false;}
			if (b.getActionCommand().equals("bs_none")){sb_2 = false; sb_1 = false;}
			if (b.getActionCommand().equals("bh_double")) {hb_2 = true; hb_1 = false;}
			if (b.getActionCommand().equals("bh_single")) {hb_1 = true; hb_2 = false;}
			if (b.getActionCommand().equals("bh_none")){hb_2 = false; hb_1 = false;}
		}
	}
	/*
	 * Actual ActionListener
	 * this will calculate all the damage etc.
	 * also the output in the JTextBox' is controlled in here
	 */
	class InputHandler implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			int rocketType = r_damage.getSelectedIndex();
			int scheepsromp = t_scheepsromp.getSelectedIndex();
			int premiejager = t_premiejager.getSelectedIndex();
			int schildenergie = t_schildenergie.getSelectedIndex();
			int raketgeleerde = t_raketgeleerde.getSelectedIndex();
			
			String getS_laser3 = s_laser3.getText();
			String getS_gen = s_gen.getText();
			String getS_shield = s_shield.getText();
			String getD_laser3 = d_laser3.getText();
			String getD_shield = d_shield.getText();
			/*
			 * those variable's are used to calculate the extra update's from boosters etc.
			 */
			double rocketDamage = 0;
			double h_scheepsromp = 0;
			double d_premiejager = 0;
			double s_schildenergie = 0;
			double r_raketgeleerde = 0;
			
			double l_extra, r_extra, s_extra, g_extra, h_extra;
			
			double dl_extra = 1, ds_extra = 1, sb_extra = 1, db_extra = 1, hb_extra = 1, 
						ul_extra = 1, us_extra = 1, ur_extra = 1, ug_extra = 1;
			
			if(des_dam == true){dl_extra = 1.05;}
			if(des_def == true){ds_extra = 1.1;}
			if(des_def == false && des_dam == false){sb_extra = 1; dl_extra = 1;}
			
			if(db_2 == true){db_extra = 1.2;}
			if(db_1 == true){db_extra = 1.1;}
			if(db_2 == false && db_1 == false){db_extra = 1;}
			
			if(sb_2 == true){sb_extra = 1.5;}
			if(sb_1 == true){sb_extra = 1.25;}
			if(sb_2 == false && sb_1 == false){sb_extra = 1;}
			
			if(hb_2 == true){hb_extra = 1.2;}
			if(hb_1 == true){hb_extra = 1.1;}
			if(hb_2 == false && hb_1 == false){hb_extra = 1;}
			
			if(doL_Seprom == true){ul_extra = 1.6;}
			if(doL_prom == true){ul_extra = 1.3;}
			if(doL_Seprom == false && doL_prom == false){ul_extra = 1;}
			if(doR_Seprom == true){ur_extra = 1.6;}
			if(doR_prom == true){ur_extra = 1.3;}
			if(doR_Seprom == false && doR_prom == false){ur_extra = 1;}
			if(doS_Seprom == true){us_extra = 1.4;}
			if(doS_prom == true){us_extra = 1.2;}
			if(doS_Seprom == false && doS_prom == false){us_extra = 1;}
			if(doG_prom == true){ug_extra = 1.2;}
			if(doG_prom == false){ug_extra = 1;}
			
			/*
			 * this is for the talent tree..
			 */
			if(premiejager == 0) {d_premiejager = 1;}
			if(premiejager == 1) {d_premiejager = 1.02;}
			if(premiejager == 2) {d_premiejager = 1.04;}
			if(premiejager == 3) {d_premiejager = 1.06;}
			if(premiejager == 4) {d_premiejager = 1.09;}
			if(premiejager == 5) {d_premiejager = 1.12;}
			
			if(schildenergie == 0) {s_schildenergie = 1;}
			if(schildenergie == 1) {s_schildenergie = 1.04;}
			if(schildenergie == 2) {s_schildenergie = 1.08;}
			if(schildenergie == 3) {s_schildenergie = 1.12;}
			if(schildenergie == 4) {s_schildenergie = 1.18;}
			if(schildenergie == 5) {s_schildenergie = 1.25;}
			
			if(raketgeleerde == 0) {r_raketgeleerde = 1;}
			if(raketgeleerde == 1) {r_raketgeleerde = 1.02;}
			if(raketgeleerde == 2) {r_raketgeleerde = 999;}
			if(raketgeleerde == 3) {r_raketgeleerde = 999;}
			if(raketgeleerde == 4) {r_raketgeleerde = 999;}
			if(raketgeleerde == 5) {r_raketgeleerde = 1.15;}
			/*
			 * this will actually calculate the total boosts for your ship 
			 */
			l_extra = 1 * dl_extra * db_extra * ul_extra * d_premiejager;	//laser
			s_extra = 1 * sb_extra * ds_extra * us_extra;					//shield
			r_extra = 1 * ur_extra;											//rocket
			g_extra = 1 * ug_extra;											//speedgen
			h_extra = 1 * hb_extra;											//hitpoints
			/*
			 * this try connects everything and make it just 1 simple number
			 */
			try {
				if (Integer.parseInt(getS_laser3) >= 0
						&& Integer.parseInt(getD_laser3) >= 0) {
					double damage = ((Integer.parseInt(getS_laser3) * 150)
							+ (Integer.parseInt(getD_laser3) * 150 * 1.1)) * l_extra;
					double damage4 = damage * 4;
					double damage6 = damage * 6;
					u_damage.setText("" + damage);
					u_damage4.setText("" + damage4);
					u_damage6.setText("" + damage6);
				}
				if (Integer.parseInt(getS_gen) >= 0) {
					double getal = ((Integer.parseInt(getS_gen) * 10)
							+ startSpeed) * g_extra;
					u_speed.setText("" + getal);
				}
				if (Integer.parseInt(getS_shield) >= 0
						&& Integer.parseInt(getD_shield) >= 0) {
					double getal = (((Integer.parseInt(getS_shield) * 10000)
							+ (Integer.parseInt(getD_shield) * 10000 * 1.2)) * s_schildenergie) * s_extra;
					u_shield.setText("" + getal);
				}
				if (rocketType == 0) {rocketDamage = 1000;}
				if (rocketType == 1) {rocketDamage = 2000;}
				if (rocketType == 2) {rocketDamage = 4000;}
				if (rocketType == 3) {rocketDamage = 8000;}
				double rocketDamageTotal = rocketDamage * r_extra * r_raketgeleerde;
				u_rDamage.setText("" + rocketDamageTotal);
				
				if(scheepsromp == 0) {h_scheepsromp = 0;}
				if(scheepsromp == 1) {h_scheepsromp = 5000;}
				if(scheepsromp == 2) {h_scheepsromp = 10000;}
				if(scheepsromp == 3) {h_scheepsromp = 15000;}
				if(scheepsromp == 4) {h_scheepsromp = 30000;}
				if(scheepsromp == 5) {h_scheepsromp = 50000;}
				double hitPoints = (startHP * h_extra) + h_scheepsromp;
				u_health.setText("" + hitPoints);
				/*
				 * checks for the amount of lasers and gen's in your ship/drone
				 */
				if (Integer.parseInt(getS_laser3) > 15 || (Integer.parseInt(getS_gen) + Integer.parseInt(getS_shield)) > 15 || 
							(Integer.parseInt(getD_laser3) + Integer.parseInt(getD_shield)) > 31){
					u_damage.setText	("TO MANY LASERS/GENS");
					u_shield.setText	("TO MANY LASERS/GENS");
					u_damage4.setText	("TO MANY LASERS/GENS");
					u_damage6.setText	("TO MANY LASERS/GENS");
					u_speed.setText		("TO MANY LASERS/GENS");
				}
			} catch (NumberFormatException nfe) {

			}
		}
	}
}